﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using DataServer;

namespace DataServer.Mail
{
    public class SendMail
    {
		private static String mailServer="172.25.200.202";
        private static String mailAdd="xm_cim_pms@tianma.cn";
        private static String mailPassword="tm@2012X";
        public static void Send(String strmail, String strMessage) 
        { 
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); 
            msg.To.Add(strmail); 
            //msg.To.Add(b@b.com); 
            /* 
            * msg.To.Add("b@b.com"); 
            * msg.To.Add("b@b.com"); 
            * msg.To.Add("b@b.com");可以发送给多人 
            */ 
            //msg.CC.Add("c@c.com"); 
            /* 
            * msg.CC.Add("c@c.com"); 
            * msg.CC.Add("c@c.com");可以抄送给多人 
            */ 
            msg.From = new MailAddress("xm_cim_pms@tianma.cn", "xm_cim", System.Text.Encoding.UTF8); 
            /* 上面3个参数分别是发件人地址（可以随便写），发件人姓名，编码*/ 
            msg.Subject = "备件库存小于安全库存";//邮件标题 
            msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码 
            msg.Body = strMessage;//邮件内容 
            msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码 
            msg.IsBodyHtml = true;//是否是HTML邮件 
            msg.Priority = MailPriority.High;//邮件优先级 

            SmtpClient client = new SmtpClient(); 
            client.Credentials = new System.Net.NetworkCredential(mailAdd, mailPassword); 
            //在zj.com注册的邮箱和密码 
            client.Host = mailServer; 
            object userState = msg; 
            try 
            { 
				client.SendAsync(msg, userState); 
				//简单一点儿可以client.Send(msg); 

            } 
            catch (System.Net.Mail.SmtpException ex) 
            { 
                //LogWrite.Log("Server", "发送邮件出错:"+ex.Message); 
            } 
        }
    }
}
